function GetWindowHeight(height) {
	var winHeight = $(window).height();
	var winHeight = winHeight - 162 > 0 ? winHeight - parseInt(height) : 500;
	return winHeight;
};

//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';

//工具集合Tools
window.T = {};

// 获取请求参数
// 使用示例
// location.href = http://localhost:8080/index.html?id=123
// T.p('id') --> 123;
var url = function(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return unescape(r[2]);
	return null;
};

T.p = url;

//全局配置
$.ajaxSetup({
	dataType : "json",
	contentType : "application/json",
	cache : false
});

//重写alert
window.alert = function(msg, callback){
	parent.layer.alert(msg, function(index){
		parent.layer.close(index);
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//重写confirm式样框
window.confirm = function(msg, callback) {
	parent.layer.confirm(msg, {
		btn : [ '确定', '取消' ]
	}, function(index) {//确定事件
		if (typeof (callback) === "function") {
			callback("ok");
		}
		parent.layer.close(index);
	});
};

//选择一条记录
function getSelectedRow(btn) {
	var grid = $("#grid");
	var rowKey = grid.getGridParam("selrow");
	if (!rowKey) {
		showWarning(btn,'请选择一条记录！');
		return;
	}

	var selectedIDs = grid.getGridParam("selarrrow");
	if (selectedIDs.length > 1) {
		showWarning(btn,'只能选择一条记录！');
		return;
	}

	return selectedIDs[0];
}

//选择多条记录
function getSelectedRows(btn) {
	var grid = $("#grid");
	var rowKey = grid.getGridParam("selrow");
	if (!rowKey) {
		showWarning(btn,'请选择一条记录！');
		return;
	}

	return grid.getGridParam("selarrrow");
}

//成功
function showSuccess(btn,msg) {
	btn.$message({
		message : msg,
		type : 'success'
	});
}

//警告
function showWarning(btn,msg){
	btn.$message({
        message: msg,
        type: 'warning'
      });
}

//失败
function showError(btn,msg){
	btn.$message.error(msg);
}